/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from "vue";
import VueRouter from "vue-router";
import Layout from "@/layouts";
import EmptyLayout from "@/layouts/EmptyLayout";
import EmptyLayoutIndex from "@/layouts/EmptyLayoutIndex";
import { publicPath, routerMode } from "@/config/settings";

Vue.use(VueRouter);
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/register",
    component: () => import("@/views/register/index"),
    hidden: true,
  },
  {
    path: "/401",
    name: "401",
    component: () => import("@/views/401"),
    hidden: true,
  },
  {
    path: "/402",
    name: "402",
    component: () => import("@/views/401"),
    hidden: true,
  },
  {
    path: "/404",
    name: "404",
    component: () => import("@/views/404"),
    hidden: true,
  },
];

export const asyncRoutes = [
  {
    path: "/",
    component: EmptyLayoutIndex,
    redirect: "/index",
    meta: {
      title: "首页",
    },
    children: [
      {
        path: "/index",
        name: "Index",
        component: () => import("@/views/coverIndex/index"),
        meta: {
          title: "首页",
        },
      },
    ],
  },
  {
    path: "/personalCenter",
    component: Layout,
    hidden: true,
    redirect: "/personalCenter",
    children: [
      {
        path: "/personalCenter",
        name: "PersonalCenter",
        component: () => import("@/views/personalCenter/index"),
        meta: {
          title: "个人中心",
        },
      },
    ],
  },
  {
    path: "/medicalCareIndex",
    component: Layout,
    hidden: true,
    redirect: "/medicalCareIndex",
    meta: {
      title: "医老人之需",
    },
    children: [
      {
        path: "/medicalCareIndex",
        name: "medicalCareIndex",
        component: () => import("@/views/medicalCare/index"),
        meta: {
          title: "首页",
        },
      },
      {
        path: "/disease1",
        name: "Disease1",
        component: () => import("@/views/medicalCare/disease1"),
        meta: {
          title: "疾病治疗",
        },
      },
      // {
      //   path: "/disease2",
      //   name: "Disease2",
      //   component: () => import("@/views/medicalCare/disease2"),
      //   meta: {
      //     title: "急性病治疗",
      //   },
      // },
      {
        path: "/disease3",
        name: "Disease3",
        component: () => import("@/views/medicalCare/disease2"),
        meta: {
          title: "慢性病管理",
        },
      },
      {
        path: "/disease4",
        name: "Disease4",
        component: () => import("@/views/medicalCare/disease3"),
        meta: {
          title: "康复训练",
        },
      },
      {
        path: "/disease5",
        name: "Disease5",
        component: () => import("@/views/medicalCare/disease4"),
        meta: {
          title: "心理慰藉",
        },
      },
      {
        path: "/disease6",
        name: "Disease6",
        component: () => import("@/views/medicalCare/disease5"),
        meta: {
          title: "安宁服务",
        },
      },
    ],
  },
  {
    path: "/badNum",
    component: Layout,
    hidden: true,
    redirect: "/badNum",
    meta: {
      title: "智能看护",
    },
    children: [
      {
        path: "/badNum",
        name: "BadNum",
        component: () => import("@/views/intelligentCare/badNum"),
        meta: {
          title: "床位",
        },
      },
      {
        path: "/toilet",
        name: "Toilet",
        component: () => import("@/views/intelligentCare/toilet"),
        meta: {
          title: "卫生间",
        },
      },
      {
        path: "/ICU",
        name: "Icu",
        component: () => import("@/views/intelligentCare/ICU"),
        meta: {
          title: "重症监护",
        },
      },
      {
        path: "/warning",
        name: "Warning",
        component: () => import("@/views/intelligentCare/warningInfo"),
        meta: {
          title: "报警信息",
        },
      },
    ],
  },
  {
    path: "/institutionalIndex",
    component: Layout,
    hidden: true,
    redirect: "/institutionalIndex",
    children: [
      {
        path: "/institutionalIndex",
        name: "InstitutionalIndex",
        component: () => import("@/views/institutionalPension/index"),
        meta: {
          title: "首页",
        },
      },
      {
        path: "/appointmentReg",
        name: "AppointmentReg",
        component: () => import("@/views/institutionalPension/appointmentReg"),
        meta: {
          title: "预约管理",
        },
      },
      {
        path: "/trymanager",
        name: "Trymanager",
        component: () => import("@/views/institutionalPension/trymanager"),
        meta: {
          title: "试住管理",
        },
      },
      {
        path: "/oldermanager",
        name: "Oldermanager",
        component: () => import("@/views/institutionalPension/oldermanager"),
        meta: {
          title: "入住管理",
        },
      },
      {
        path: "/bedmanager",
        name: "Bedmanager",
        redirect: "noRedirect",
        component: EmptyLayout,
        meta: {
          title: "床位管理",
        },
        children: [
          {
            path: "bedList",
            name: "BedList",
            component: () =>
              import("@/views/institutionalPension/bedmanager/bedmanager"),
            meta: { title: "床位管理" },
          },
          {
            path: "buildingmanager",
            name: "Buildingmanager",
            component: () =>
              import("@/views/institutionalPension/bedmanager/buildingmanager"),
            meta: { title: "楼栋管理" },
          },
          {
            path: "bedType",
            name: "BedType",
            component: () =>
              import("@/views/institutionalPension/bedmanager/bedType"),
            meta: { title: "床位类型" },
          },
        ],
      },
      {
        path: "/costmanager",
        name: "Costmanager",
        redirect: "noRedirect",
        component: EmptyLayout,
        meta: {
          title: "费用管理",
        },
        children: [
          {
            path: "/nursingcost",
            name: "Nursingcost",
            component: () =>
              import("@/views/institutionalPension/costmanager/nursingcost"),
            meta: {
              title: "护理费用",
            },
          },
          {
            path: "/foodcost",
            name: "Foodcost",
            component: () =>
              import("@/views/institutionalPension/costmanager/foodcost"),
            meta: {
              title: "餐饮费用",
            },
          },
        ],
      },
      {
        path: "/nursemanager",
        name: "Nursemanager",
        component: () => import("@/views/institutionalPension/nursemanager"),
        meta: {
          title: "护工管理",
        },
      },
    ],
  },
  {
    path: "/doorService",
    component: Layout,
    hidden: true,
    redirect: "/doorService",
    children: [
      {
        path: "/doorService",
        name: "DoorService",
        component: () => import("@/views/doorService/index"),
        meta: { title: "首页" },
      },
      {
        path: "/bodyService",
        name: "BodyService",
        component: () => import("@/views/doorService/testBody"),
        meta: { title: "流动服务车" },
      },
      {
        path: "/civilService",
        name: "CivilService",
        component: () => import("@/views/doorService/doorService"),
        meta: { title: "上门服务" },
      },
      {
        path: "/personManager",
        name: "PersonManager",
        component: () => import("@/views/doorService/personManager"),
        meta: { title: "服务人员管理" },
      },
    ],
  },
  {
    path: "/map",
    component: Layout,
    redirect: "/map",
    hidden: true,
    children: [
      {
        path: "/map",
        component: () => import("@/views/map/index"),
        name: "Map",
        meta: {
          title: "地图",
        },
      },
      {
        path: "/mapData",
        name: "MapData",
        redirect: "noRedirect",
        component: EmptyLayout,
        meta: {
          title: "地图数据",
        },
        children: [
          {
            path: "yanglaojigou",
            name: "Yanglaojigou",
            component: () => import("@/views/map/olderData.vue"),
            meta: { title: "养老机构" },
          },
          {
            path: "fuwujigou",
            name: "Fuwujigou",
            component: () => import("@/views/map/serveData.vue"),
            meta: { title: "服务机构" },
          },
        ],
      },
    ],
  },
  {
    path: "/healthData",
    component: Layout,
    hidden: true,
    redirect: "/healthData",
    children: [
      {
        path: "/healthData",
        name: "HealthData",
        component: () => import("@/views/healthRecords/index"),
        meta: {
          title: "健康档案大数据",
        },
      },
      {
        path: "/healthRecords",
        name: "HealthRecords",
        component: () => import("@/views/healthRecords/list"),
        meta: {
          title: "老人健康管理档案",
        },
      },
    ],
  },
  {
    path: "/trainingCourse",
    component: Layout,
    hidden: true,
    redirect: "/trainingCourse",
    children: [
      {
        path: "/trainingCourse",
        name: "TrainingCourse",
        component: () => import("@/views/course/huliCourse"),
        meta: {
          title: "护理知识",
        },
      },
      {
        path: "/lineCourse",
        name: "LineCourse",
        component: () => import("@/views/course/lineCourse"),
        meta: {
          title: "在线培训",
        },
      },
      {
        path: "/yiliaoCourse",
        name: "YiliaoCourse",
        component: () => import("@/views/course/yiliaoCourse"),
        meta: {
          title: "医疗小知识",
        },
      },
    ],
  },
  {
    path: "/entertainment",
    component: Layout,
    hidden: true,
    redirect: "/entertainment",
    children: [
      {
        path: "/entertainment",
        name: "Entertainment",
        component: () => import("@/views/entertainment/interest.vue"),
        meta: {
          title: "兴趣小课堂",
        },
      },
      {
        path: "/bodybuilding",
        name: "Bodybuilding",
        component: () => import("@/views/entertainment/bodybuilding.vue"),
        meta: {
          title: "健身运动",
        },
      },
      {
        path: "/food",
        name: "Food",
        component: () => import("@/views/entertainment/food"),
        meta: {
          title: "饮食与养身",
        },
      },
    ],
  },
  {
    path: "/materialReceiving",
    component: Layout,
    hidden: true,
    redirect: "/materialReceiving",
    children: [
      {
        path: "/materialReceiving",
        name: "MaterialReceiving",
        component: () => import("@/views/helpManager/materialReceiving"),
        meta: {
          title: "物资接收",
        },
      },
      {
        path: "/materialDistribution",
        name: "MaterialDistribution",
        component: () => import("@/views/helpManager/materialDistribution"),
        meta: {
          title: "物资分配",
        },
      },
    ],
  },
  {
    path: "/error",
    component: EmptyLayout,
    redirect: "noRedirect",
    hidden: true,
    name: "Error",
    meta: { title: "错误页", icon: "bug" },
    children: [
      {
        path: "401",
        name: "Error401",
        component: () => import("@/views/401"),
        meta: { title: "401" },
      },
      {
        path: "404",
        name: "Error404",
        component: () => import("@/views/404"),
        meta: { title: "404" },
      },
    ],
  },
  {
    path: "*",
    redirect: "/404",
    hidden: true,
  },
];

const router = new VueRouter({
  base: routerMode === "history" ? publicPath : "",
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
});
//注释的地方是允许路由重复点击，如果你觉得框架路由跳转规范太过严格可选择放开
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch((err) => err);
};

export function resetRouter() {
  router.matcher = new VueRouter({
    base: routerMode === "history" ? publicPath : "",
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  }).matcher;
}

export default router;
